package chapter20;

import java.util.Collections;
import java.util.PriorityQueue;

/**
 * @program: exercise
 * @description: 优先队列存储字符串的例子
 * @author: 陈庆彪
 * @create: 2020-02-22 16:36
 **/
public class PriorityQueueDeom {
    public static void main(String[] args) {
        PriorityQueue queue1=new PriorityQueue<>();
        queue1.offer("beijing");
        queue1.offer("shanghai");
        queue1.offer("wuhan");
        queue1.offer("nanjing");
        queue1.offer("hangzhou");
        System.out.println("priority queue1 using comparable: "); //自然顺序排列 按先进先出原则依次删除
        while (queue1.size()>0){
            System.out.print(queue1.remove()+" ");
        }
        PriorityQueue queue2=new PriorityQueue(1, Collections.reverseOrder());//指定优先级 翻转自然顺序 依次删除
        queue2.offer("beijing");
        queue2.offer("wuhan");
        queue2.offer("shanghai");
        queue2.offer("nanjing");
        queue2.offer("hangzhou");
        System.out.println("\npriority queue2 using comparable: ");
        while (queue2.size()>0){
            System.out.print(queue2.remove()+" ");
        }
    }
}
